<template>
  <el-dialog
    title="订单发货"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="100px" size="small">
      <el-form-item label="改派订单:" prop="shopId">
        <el-select v-model="dataForm.shopId">
          <el-option
            v-for="item in merList"
            :key="item.id"
            :label="item.shopName"
            :value="item.id"
          ></el-option>
        </el-select>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button size="small" @click="visible = false">取消</el-button>
      <el-button size="small" type="primary" @click="dataFormSubmit()">提交</el-button>
    </span>
  </el-dialog>
</template>
<script>
  import {changeObj} from '@/api/order/order'
  import {getShopListByMerTypeId} from '@/api/shop/shops'

  export default {
    data () {
      return {
        dataForm: {
          orderId: '',
          shopId: '',
          merTypeId: ''
        },
        visible: false,
        dataListLoading: false,
        shipmentVisible: false,
        shipmentListLoading: false,
        mapForm: {},
        merList: [],
      }
    },
    components: {},
    methods: {
      init (id,merTypeId,shopId) {
        this.dataForm.merTypeId = merTypeId
        this.dataForm.orderId = id || 0
        this.dataForm.shopId = shopId
        this.visible = true
          if (this.dataForm.orderId) {
            const data = new FormData()
            data.append('orderId', this.dataForm.orderId)
            data.append('merTypeId', this.dataForm.merTypeId)
            getShopListByMerTypeId(data)
              .then((res) => {
                console.log('qqq',res)
                this.merList = res.data.data
              })
          }
      },

      // 表单提交
      dataFormSubmit () {
        const params = new FormData()
        params.append('shopId', this.dataForm.shopId)
        params.append('orderId', this.dataForm.orderId)
        changeObj(params).then(res => {
          console.log(res)
          this.$message({
            message: '改派成功',
            type: 'success',
          })
          this.visible = false
          this.$emit('refreshDataList')
        })
      },
    }
  }
</script>
